﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using csv2json.convert.objConverter;

namespace csv2json
{
    public partial class Form1 : Form
    {
        String content2Json = "";

        public Form1()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            openFileDialog.Multiselect = false;
            openFileDialog.Filter = "XLSX file (*.xlsx)|*.xlsx";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                String fileName = openFileDialog.FileName;
                tbOpen.Text = fileName;

                switch (openFileDialog.SafeFileName)
                {
                    case "Penguin.xlsx":
                        PenguinConverter penConverter = new PenguinConverter(fileName);
                        content2Json = penConverter.convert();
                        break;
                }
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                StreamWriter writer = new StreamWriter(saveFileDialog.FileName);
                writer.Write(content2Json);

                writer.Close();
                MessageBox.Show("Completed");
            }
        }
    }
}
